
package ua.trasferta.task17;

import static ua.trasferta.common.team.TeamMember.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import ua.trasferta.common.annotations.createBy;

/**
 * <p>
 * Cruel agent and brave spy<br>
 * Fight below the blue sky.<br>
 * Bus time schedule should decide,<br>
 * Who did wrong and who did right.<br>
 * </p>
 * 
 * @author Anton Podviaznikov
 */
@createBy(authors = {ANTON_KAYDALOV, ALEXEI_FILONOV, ANTON_PODVIAZNIKOV, KATERYNA_TULUZOVA, YULIA_FIL, MARYNA_ALEKSANDROVA,
		ANDREY_ZHDANOV, TETIANA_LEVENDOVSKAYA})
public class Task17
{
	private static final String ERROR_MESSAGE = "Incorrect input";

	public static void main(String[] args)
	{
		String fn = args[0];
		try
		{
			BufferedReader in = new BufferedReader(new FileReader(fn));
			String[] ss = in.readLine().split(" ");
			int L = Integer.parseInt(ss[0]);
			int N = Integer.parseInt(ss[1]);
			int[] intervals = new int[N];
			ss = in.readLine().split(" ");
			for (int i = 0; i < N; ++i)
			{
				intervals[i] = Integer.parseInt(ss[i]);
			}
			boolean catched = false;
			int lateCurrent = L;
			for (int i = 0; i < N; ++i)
			{
				int intervalCurrent = intervals[i];
				if (lateCurrent <= intervalCurrent)
				{
					catched = true;
					// System.out.println(i);
					break;
				}
				else
				{
					int lateTmp = lateCurrent - intervalCurrent;
					if (lateTmp % intervalCurrent == 0)
					{
						lateCurrent = lateTmp;
					}
					else
					{
						lateCurrent = (lateTmp / intervalCurrent) * intervalCurrent;
					}
				}
			}
			System.out.println(catched ? "1" : "0");
		}
		catch (FileNotFoundException e)
		{
			System.out.println(ERROR_MESSAGE);
		}
		catch (IOException e)
		{
			System.out.println(ERROR_MESSAGE);
		}
	}
}
